package com.biboheart.adapter.compiler;

import com.biboheart.adapter.compiler.Compiler;
import com.biboheart.adapter.compiler.Grammar;
import com.biboheart.adapter.compiler.Lexical;
import com.biboheart.adapter.compiler.ast.Node;
import com.biboheart.adapter.compiler.grammar.GrammarImpl;
import com.biboheart.adapter.compiler.lexical.LexicalDefault;
import com.biboheart.adapter.compiler.token.Token;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

public class NormalCompiler implements Compiler {
    @Override
    public Node build(String expr) {
        if (StringUtils.isEmpty(expr)) {
            return null;
        }
        Lexical lexical = new LexicalDefault();
        Grammar grammar = new GrammarImpl();
        List<Token> tokenList = lexical.analysis(expr);
        /*try {
            System.out.println(JsonUtils.obj2json(tokenList));
        } catch (JsonProcessingException e) {
            throw new RuntimeException(e);
        }*/
        return grammar.analysis(tokenList);
    }
}
